home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / tools / ebsx130 / gaiji.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-19  |  8.0 KB  |  376 lines

  1. /* EB.X V1.10 
  2.    1995.9.3 鈴木 健児 */
  3.  
  4. #include "common.h"
  5.  
  6. #include <iocslib.h>
  7. #include <jctype.h>
  8. #include <method\Dos_i.h>
  9.  
  10. int    set_gaiji2( int , unsigned int );
  11. int    set_gaiji1( int , unsigned int );
  12. int    reset_gaiji( void );
  13. int    set_gaiji_ebg( int , unsigned int );
  14. int    reset_gaiji_ebg( void );
  15. int    nextcode( int );
  16. int    nextcodejis( int );
  17.  
  18. static    struct    FNTBUF    fnttbl[ 190 ];        /* 元々登録してあった外字を保存する */
  19. int    fnttblptr;
  20. unsigned short    f2jisst , f2jised , f2jismax;
  21. unsigned short    f1jisst , f1jised , f1jismax;
  22. unsigned short    f2ascst , f2asced , f2ascmax;
  23. unsigned char    f2esc;
  24.  
  25. /* char    fn2[ ] = "j:\\crger\\start" ; */
  26. /* char    fn2[ ] = "f:\\fss\\start" ; */
  27. /* char    fn2[ ] = "j:\\jirin\\start" ; */
  28.  
  29. /*
  30. int main(int argc, char *argv[])
  31. {
  32.     unsigned short rootpagenumber;
  33.     int    code;
  34.  
  35.     cdfile = fopen( fn2 , "rb" );
  36.     if( cdfile == NULL)
  37.     {
  38.         printf( "Error ファイルがオープンできません\n" );
  39.         return( 0 );
  40.     };
  41.  
  42.  
  43.     rootpagenumber = search_rootindexpos2( 0xf200 );
  44.     if( rootpagenumber == 0 )
  45.     {
  46.         return( 0 );
  47.     };
  48.     DOSSEEK( cdfile , rootpagenumber*0x800 , SEEK_SET );
  49.     code = set_gaiji2( 0xeb9f );
  50.     printf( "\ncode2 = %x\n" , code );
  51.  
  52.     DOSSEEK( cdfile , 0 , SEEK_SET );
  53.     rootpagenumber = search_rootindexpos2( 0xf100 );
  54.     if( rootpagenumber == 0 )
  55.     {
  56.         return( 0 );
  57.     };
  58.     DOSSEEK( cdfile , rootpagenumber*0x800 , SEEK_SET );
  59.     code = set_gaiji1( code );
  60.     printf( "\ncode1 = %x\n" , code );
  61.  
  62.     return( 0 );
  63. }
  64.  
  65.  
  66. unsigned short    search_rootindexpos2( unsigned short target )
  67. {
  68.     unsigned short saizu;
  69.     unsigned short data;
  70.     unsigned short retcode;
  71.     int i;
  72.  
  73.     DOSREAD( cdfile , &saizu , sizeof( unsigned short ) , 1 , cdfile );    
  74.     DOSSEEK( cdfile , 16 , SEEK_SET );
  75.  
  76.     i = 0;
  77.     retcode = 0;
  78.     while( (i < saizu) && retcode == 0 )
  79.     {
  80.         DOSREAD( &data , sizeof( unsigned short ) , 1 , cdfile );    
  81.     printf( "data =%x\n" , data );
  82.         if( (data & 0xff00 ) == target )
  83.         {
  84.             DOSSEEK( cdfile , 2 , SEEK_CUR );
  85.             DOSREAD( &retcode , sizeof( unsigned short ) , 1 , cdfile );    
  86.         } else {
  87.             DOSSEEK( cdfile , 14 , SEEK_CUR );
  88.         };
  89.         i++;
  90.     };
  91.  
  92.     return( retcode );
  93. }
  94. */
  95.  
  96. /* set_gaiji2()、set_gaiji1()の順でコールすること fnttblptrの関係 */
  97. /* 半角 f200 はこれで良いらしい 0xa121~に対応 */
  98. int    set_gaiji2( int code , unsigned int pagenum )
  99. {
  100.     int i , o , k , stat;
  101.     int count;
  102.     unsigned short numofgaiji;
  103.     unsigned char bitpatan;
  104.     unsigned char patan[ 32 ];
  105.  
  106.     DOSSEEK( cdfile , pagenum*0x800 , SEEK_SET );
  107.     DOSSEEK( cdfile , 10 , SEEK_CUR );
  108.     DOSREAD( cdfile , &f2jisst , sizeof( unsigned short ) );
  109.     DOSREAD( cdfile , &numofgaiji , sizeof( unsigned short ) );    
  110.  
  111.     /* 外字の終わりのコード(JIS)を得る */
  112.     f2jised = f2jisst;
  113.     for( count=0; count < (numofgaiji-1); count++ )
  114.     {
  115.         f2jised = nextcodejis( f2jised );
  116.     };
  117. /* printf( "gaiji = %4x , %4x , %d\n" , f2jisst , f2jised , numofgaiji ); */
  118.     f2jismax = f2jisst-1;
  119.  
  120.     DOSSEEK( cdfile , (pagenum+1)*0x800 , SEEK_SET );
  121.  
  122. /*    code = JISSFT( 0x7721 ); */
  123.     i = 0;
  124.  
  125.     for( count=0; count<numofgaiji; count++ )
  126.     {
  127.         for( o=0; o<16; o++ )
  128.         {
  129.             DOSREAD( cdfile , &bitpatan , sizeof( unsigned char ) );    
  130.             patan[ o*2   ] = bitpatan;
  131.             patan[ o*2+1 ] = 0;
  132.         };
  133.  
  134.         stat = FNTGET( 8 , code , &fnttbl[ i ] );
  135.         k = DEFCHR( 8 , code , patan );
  136. /*    printf( "i=%x c=%4x %c%c : " , i , code , code >> 8 , code & 0x00ff ); */
  137.         codetbl2[ i ] = code;
  138.  
  139.         f2jismax = nextcodejis( f2jismax );
  140.         code = nextcode( code );
  141.         if( code == -1 )
  142.         {
  143.             count = numofgaiji;
  144.             puts( "外字の数が多すぎます\n" );
  145.         };
  146.         i++;
  147.     };
  148.     codetbl2[ i ] = 0xffff;
  149.  
  150. /* printf( "gaijimax = %4x" , f2jismax ); */
  151.     fnttblptr = i;
  152.     return( code );
  153. }
  154.  
  155. /* set_gaiji2()、set_gaiji1()の順でコールすること fnttblptrの関係 */
  156. /* 全角 f100 はこれで良いらしい 0xa421~に対応する */
  157. int    set_gaiji1( int code , unsigned int pagenum )
  158. {
  159.     int i , o , k , stat;
  160.     int count;
  161.     unsigned short numofgaiji;
  162.     unsigned char bitpatan;
  163.     unsigned char patan[ 32 ];
  164.  
  165.     DOSSEEK( cdfile , pagenum*0x800 , SEEK_SET );
  166.     DOSSEEK( cdfile , 10 , SEEK_CUR );
  167.     DOSREAD( cdfile , &f1jisst , sizeof( unsigned short ) );    
  168.     DOSREAD( cdfile , &numofgaiji , sizeof( unsigned short ) );    
  169.  
  170.     /* 外字の終わりのコード(JIS)を得る */
  171.     f1jised = f1jisst;
  172.     for( count=0; count < (numofgaiji-1); count++ )
  173.     {
  174.         f1jised = nextcodejis( f1jised );
  175.     };
  176. /* printf( "gaiji = %4x , %4x , %d\n" , f1jisst , f1jised , numofgaiji ); */
  177.     f1jismax = f1jisst-1;
  178.     DOSSEEK( cdfile , (pagenum+1)*0x800 , SEEK_SET );
  179.  
  180.     if( code < 0 )
  181.     {
  182.         return( code );
  183.     };
  184.  
  185. /*    j = JISSFT( 0x7621 ); */
  186.  
  187.     i = 0;
  188.     for( count=0; count<numofgaiji; count++ )
  189.     {
  190.         for( o= 0 ; o<32 ; o++)
  191.         {
  192.             DOSREAD( cdfile , &bitpatan , sizeof( unsigned char ) );    
  193.             patan[ o ] = bitpatan;
  194.         };
  195.         stat = FNTGET( 8 , code , &fnttbl[ i+fnttblptr ] );
  196.         k = DEFCHR( 8 , code , patan );
  197. /*    printf( "i=%x c=%4x:%c%c : " , i , code , code >> 8 , code & 0x00ff ); */
  198.         codetbl1[ i ] = code;
  199.  
  200.         f1jismax = nextcodejis( f1jismax );
  201.         code = nextcode( code );
  202.         if( code == -1 )
  203.         {
  204.             count = numofgaiji;
  205.             puts( "外字の数が多すぎます\n" );
  206.         };
  207.         i++;
  208.     };
  209.     codetbl1[ i ] = 0xffff;
  210. /* printf( "gaijimax = %4x" , f1jismax ); */
  211.  
  212.     return( code );
  213. }
  214.  
  215. int reset_gaiji( void )
  216. {
  217.     int    i , j , stat;
  218.  
  219.     i = 0;
  220.     while( codetbl2[ i ] != 0xffff )
  221.     {
  222.         stat = DEFCHR( 8 , codetbl2[ i ] , fnttbl[ i ].buffer );
  223.         i++;
  224.     };
  225.  
  226.     j = i;
  227.     i = 0;
  228.     while( codetbl1[ i ] != 0xffff )
  229.     {
  230.         stat = DEFCHR( 8 , codetbl1[ i ] , fnttbl[ i+j ].buffer );
  231.         i++;
  232.     };
  233.  
  234.     return( 0 );
  235. }
  236.  
  237. /* set_gaiji_ebg()、EBG形式の電子ブック用 */
  238. /* 半角 f200 */
  239. int    set_gaiji_ebg( int code , unsigned int pagenum )
  240. {
  241.     int i , j , o , k , stat , flg;
  242.     unsigned short numofgaiji;
  243.     unsigned char bitpatan;
  244.     unsigned char patan[ 32 ];
  245.  
  246.     DOSSEEK( cdfile , pagenum*0x800 , SEEK_SET );
  247.     DOSSEEK( cdfile , 10 , SEEK_CUR );
  248.     DOSREAD( cdfile , &f2ascst , sizeof( unsigned short ) );    
  249.     DOSREAD( cdfile , &numofgaiji , sizeof( unsigned short ) );    
  250.  
  251.     f2esc = ( f2ascst >> 8 );
  252.     f2ascst = ( f2ascst & 0x00ff );
  253.     /* 外字の終わりのコードを得る */
  254.     f2asced = f2ascst + numofgaiji;
  255.     if( f2asced > 255 )
  256.     {
  257.         f2asced = 255;
  258.     };
  259.  /* printf( "gaiji = %4x , %4x , %d\n" , f2ascst , f2asced , numofgaiji ); */
  260.     f2ascmax = f2ascst-1;
  261.     DOSSEEK( cdfile , (pagenum+1)*0x800 , SEEK_SET );
  262.  
  263. /*    code = JISSFT( 0x7721 ); */
  264.     i = 0;
  265.     for( j=f2ascst; j<=f2asced; j++ )
  266.     {
  267.         flg = 1;
  268.         for( o=0; o<16; o++ )
  269.         {
  270.             DOSREAD( cdfile , &bitpatan , sizeof( unsigned char ) );    
  271.             patan[ o*2   ] = bitpatan;
  272.             patan[ o*2+1 ] = 0;
  273.             if( bitpatan != 0 )
  274.             {
  275.                 flg = 0;
  276.             };
  277.         };
  278.         if( flg == 0 )
  279.         {
  280.             stat = FNTGET( 8 , code , &fnttbl[ i ] );
  281.             k = DEFCHR( 8 , code , patan );
  282. /*    printf( "i=%x c=%4x %c%c : " , i , code , code >> 8 , code & 0x00ff ); */
  283.             codetblebg[ j ] = code;
  284.  
  285.             f2ascmax++;
  286.             code = nextcode( code );
  287.             if( code == -1 )
  288.             {
  289.                 flg = 1;
  290.                 puts( "外字の数が多すぎます\n" );
  291.             };
  292.             i++;
  293.         } else {
  294.             codetblebg[ j ] = 0xffff;
  295.         };
  296.     };
  297. /* printf( "gaijimax = %4x" , f2ascmax ); */
  298.  
  299.     return( code );
  300. }
  301.  
  302. int reset_gaiji_ebg( void )
  303. {
  304.     int    i , j , stat;
  305.  
  306.     i = 0;
  307.     for( j=0; j<256; j++ )
  308.     {
  309.         if( codetblebg[ j ] != 0xffff )
  310.         {
  311.             stat = DEFCHR( 8 , codetblebg[ j ] , fnttbl[ i ].buffer );
  312.             i++;
  313.         };
  314.     };
  315.  
  316.     return( 0 );
  317. }
  318.  
  319. /* in sjis code */
  320. int    nextcode( int code )
  321. {
  322.     code++;
  323.     /* 0xebfd ~ 0xec3f をとばす */
  324.     if( code == 0xebfd  )
  325.     {
  326.         code = 0xec40;
  327.     };
  328.     /* 0xec7f をとばす */
  329.     if( code == 0xec7f  )
  330.     {
  331.         code++;
  332.     };
  333.     /* 外字エリアの範囲を越えた */
  334.     if( code > 0xec9e )
  335.     {
  336.         code = -1;
  337.     };
  338.  
  339.     return( code );
  340. }
  341.  
  342. int    nextcodejis( int code )
  343. {
  344.     code++;
  345.     if( ( code & 0x00ff ) == 0x7f ) 
  346.     {
  347.         code += (( 0x0121 - 0x007e )-1 ) ;
  348.     };
  349.  
  350.     return( code );
  351. }
  352.  
  353. /*
  354. void printdump( )
  355. {
  356.     int i , j ;
  357.     unsigned short data;
  358.     int sjis;
  359.     int ch,cl;
  360.  
  361.     for( i=0;i<128;i++)
  362.     {
  363.         printf( "%2d  "  , i );
  364.         for( j=0;j<8;j++)
  365.         {
  366.             DOSREAD( &data , sizeof( unsigned short ) , 1 , cdfile );
  367.             sjis = JISSFT( data );
  368.             ch = ( sjis & 0xff00 ) >> 8;
  369.             cl = sjis & 0x00ff ;
  370.             printf( "%4x:%c%c " , data , ch , cl );
  371.         };
  372.         printf( "\n" );
  373.     };
  374. }
  375. */
  376.